﻿using BusinessLayer.Dal;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace Biz
{
    [Table("Categories")]
    public class Category
    {
        public Category()
        {
            IsDeleted = false;
        }

        [Required]
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        [Required]
        public string Name { get; set; }
        public Boolean IsDeleted { get; set; }
        public virtual List<Product> Products { get; set; }
        public virtual List<Property> Properties { get; set; }
        // public virtual List<Manufacturer> Manufacturers { get; set; }

        public List<Manufacturer> GetAllManufactures(DatabaseContext db)
        {
            var mans = db.Manufacturers.SqlQuery("SELECT dbo.Manufacturers.Id, dbo.Manufacturers.Name, dbo.Manufacturers.Comment FROM dbo.Manufacturers, dbo.Products WHERE dbo.Manufacturers.Id = dbo.Products.Manufacturer_Id AND dbo.Products.Category_Id=" + Id).ToList();
            return mans;
        }

        CategoryDal dal = new CategoryDal();
        public List<Category> GetAll()
        {
            return dal.GetAllCategory();
        }
        public Category GetById(int id)
        {
            return dal.GetById(id);
        }
        
        public int Insert()
        {
            return dal.Insert(this);
        }
        public int Update()
        {
            return dal.Update(this);
        }

        public void Delete()
        {
            dal.Delete(this);
        }
        public override string ToString()
        {
            return Name;
        }
    }
}